﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CTVC.Platform.LoadTest
{
    public sealed class Common
    {
        public static int Fibonacci(string pwzArgument)
        {
            int n;
            if (int.TryParse(pwzArgument, out n))
            {
                if (n > 50)
                {
                    //ERROR_BUFFER_OVERFLOW
                    NativeMethods.SetLastError(111);
                    throw new ArgumentOutOfRangeException("n > 50");
                }
                return Fibonacci(n);
            }
            else
            {
                //ERROR_BAD_ARGUMENTS
                NativeMethods.SetLastError(160);
                throw new ArgumentException(pwzArgument);
            }
        }

        private static int Fibonacci(int n)
        {
            if (n <= 1)
                return 1;
            else
                return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
    }
}
